from django.shortcuts import render

# Create your views here.
from rest_framework.viewsets import GenericViewSet
from rest_framework.response import Response
from rest_framework.decorators import list_route
from .serializer import *


class AccountsGenericViewSet(GenericViewSet):

    @list_route(methods=["POST"])
    def get_code(self,request):
        serializer=RegCodeSerializers(data=request.data)
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)

    @list_route(methods=['POST'])
    def reg(self,request):
        serializer=NewUserSerializers(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response('ok')

    @list_route(methods=['POST'])
    def login(self, request):
        serializer=UserLoginSerializer(data=request.data,context=locals())
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)


